PROCEDURE TForm4.TestShlWAPISHAnsiToUnicode(Sender : TObject);
//Support for function as ordinal 215 under Win 98 SE (with IE 5.0) confirmed !!!
//Support for function as ordinal 215 under NT 4.0 with IE 5.0 confirmed !!!
VAR srcansibuf : STRING;
VAR srcstrlen : INTEGER;
VAR destwcharbuf : ARRAY[0..64] OF WideChar;
VAR destbufsize : INTEGER;
VAR apiretval : INTEGER;
VAR errorcode : INTEGER;
VAR newinfoline : STRING;
BEGIN
srcansibuf := '';
FillChar(destwcharbuf, SizeOf(destwcharbuf), #0);
destbufsize := 0;
apiretval := 0;
errorcode := 0;
newinfoline := '';
SetLastError(NO_ERROR);
//errorcode := INTEGER(GetLastError()); //uncomment to verify that the last error PRIOR to the function call is 0
srcansibuf := 'Hello Ansi to Unicode World';
srcstrlen := Length(srcansibuf);
destbufsize := Length(destwcharbuf);
newinfoline := 'SHAnsiToUnicode called with source string "' + srcansibuf + '" (length: ' + IntToStr(srcstrlen) +
') returned : ';
//errorcode := INTEGER(GetLastError()); //uncomment to determine the last error prior to the function call
SetLastError(NO_ERROR);
apiretval := SHAnsiToUnicode(PChar(srcansibuf), destwcharbuf, destbufsize);
//errorcode := INTEGER(GetLastError()); //uncomment to determine the last error after the function call
IF apiretval > 0 THEN
newinfoline := newinfoline + IntToStr(apiretval) + ' and in the dest buffer : "' + destwcharbuf + '"'
ELSE
BEGIN
errorcode := INTEGER(GetLastError());
newinfoline := newinfoline + IntToStr(apiretval) + ' (the function call FAILED !), GetLastError returned : ' +
IntToStr(errorcode);
END;
Memo1.Lines.Add(newinfoline);
//errorcode := INTEGER(GetLastError()); //uncomment to determine the last error after the function call
//Dest buffer length parameter set to 23 (too short by 5 character)
FillChar(destwcharbuf, SizeOf(destwcharbuf), #0);
destbufsize := 23;
apiretval := 0;
newinfoline := '';
errorcode := 0;
newinfoline := 'SHAnsiToUnicode called with source string "' + srcansibuf + '" (length: ' + IntToStr(srcstrlen) +
') returned : ';
SetLastError(NO_ERROR);
apiretval := SHAnsiToUnicode(PChar(srcansibuf), destwcharbuf, destbufsize);
IF apiretval > 0 THEN
BEGIN
errorcode := INTEGER(GetLastError());
newinfoline := newinfoline + IntToStr(apiretval) + ' and in the dest buffer : "' + destwcharbuf + '"';
Memo1.Lines.Add(newinfoline);
newinfoline := 'and GetLastError returned : ' + IntToStr(errorcode);
END
ELSE
BEGIN
errorcode := INTEGER(GetLastError());
newinfoline := newinfoline + IntToStr(apiretval) + ' (the function call FAILED !), GetLastError returned : ' +
IntToStr(errorcode);
END;
Memo1.Lines.Add(newinfoline);
//Dest buffer length parameter set to 2 (too short by 26 characters)
FillChar(destwcharbuf, SizeOf(destwcharbuf), #0);
destbufsize := 2;
apiretval := 0;
newinfoline := '';
errorcode := 0;
newinfoline := 'SHAnsiToUnicode called with source string "' + srcansibuf + '" (length: ' + IntToStr(srcstrlen) +
') returned : ';
SetLastError(NO_ERROR);
apiretval := SHAnsiToUnicode(PChar(srcansibuf), destwcharbuf, destbufsize);
IF apiretval > 0 THEN
BEGIN
errorcode := INTEGER(GetLastError());
newinfoline := newinfoline + IntToStr(apiretval) + ' and in the dest buffer : "' + destwcharbuf + '"';
Memo1.Lines.Add(newinfoline);
newinfoline := 'and GetLastError returned : ' + IntToStr(errorcode);
END
ELSE
BEGIN
errorcode := INTEGER(GetLastError());
newinfoline := newinfoline + IntToStr(apiretval) + ' (the function call FAILED !), GetLastError returned : ' +
IntToStr(errorcode);
END;
Memo1.Lines.Add(newinfoline);
//Dest buffer length parameter set to 1 (too short by 27 characters)
FillChar(destwcharbuf, SizeOf(destwcharbuf), #0);
destbufsize := 1;
apiretval := 0;
newinfoline := '';
errorcode := 0;
newinfoline := 'SHAnsiToUnicode called with source string "' + srcansibuf + '" (length: ' + IntToStr(srcstrlen) +
') returned : ';
SetLastError(NO_ERROR);
apiretval := SHAnsiToUnicode(PChar(srcansibuf), destwcharbuf, destbufsize);
IF apiretval > 0 THEN
BEGIN
errorcode := INTEGER(GetLastError());
newinfoline := newinfoline + IntToStr(apiretval) + ' and in the dest buffer : "' + destwcharbuf + '"';
Memo1.Lines.Add(newinfoline);
newinfoline := 'and GetLastError returned : ' + IntToStr(errorcode);
END
ELSE
BEGIN
errorcode := INTEGER(GetLastError());
newinfoline := newinfoline + IntToStr(apiretval) + ' (the function call FAILED !), GetLastError returned : ' +
IntToStr(errorcode);
END;
Memo1.Lines.Add(newinfoline);
//Dest buffer length parameter set to 0
FillChar(destwcharbuf, SizeOf(destwcharbuf), #0);
destbufsize := 0;
apiretval := 0;
newinfoline := '';
errorcode := 0;
SetLastError(NO_ERROR);
newinfoline := 'SHAnsiToUnicode called with source string "' + srcansibuf + '" (length: ' + IntToStr(srcstrlen) +
') returned : ';
apiretval := SHAnsiToUnicode(PChar(srcansibuf), destwcharbuf, destbufsize);
IF apiretval > 0 THEN
newinfoline := newinfoline + IntToStr(apiretval) + ' and in the dest buffer : "' + destwcharbuf + '"'
ELSE
BEGIN
errorcode := INTEGER(GetLastError());
newinfoline := newinfoline + IntToStr(apiretval) + ' (the function call FAILED !), GetLastError returned : ' +
IntToStr(errorcode);
END;
Memo1.Lines.Add(newinfoline);
//No dest buffer (pointer param set to NIL)
//and buffer length parameter set to 0
FillChar(destwcharbuf, SizeOf(destwcharbuf), #0);
destbufsize := 0;
apiretval := 0;
newinfoline := '';
errorcode := 0;
SetLastError(NO_ERROR);
newinfoline := 'SHAnsiToUnicode called with source string "' + srcansibuf + '" (length: ' + IntToStr(srcstrlen) +
') returned : ';
apiretval := SHAnsiToUnicode(PChar(srcansibuf), NIL, 0);
IF apiretval > 0 THEN
newinfoline := newinfoline + IntToStr(apiretval) + ' and in the dest buffer : "' + destwcharbuf + '"'
ELSE
BEGIN
errorcode := INTEGER(GetLastError());
newinfoline := newinfoline + IntToStr(apiretval) + ' (the function call FAILED !), GetLastError returned : ' +
IntToStr(errorcode);
END;
Memo1.Lines.Add(newinfoline);
Memo1.Lines.Add('');
END; |